package rrrmai.viewbinder;

import android.arch.persistence.room.Entity;
import android.arch.persistence.room.Index;
import android.arch.persistence.room.PrimaryKey;
import android.databinding.BaseObservable;
import android.databinding.Bindable;
import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.NonNull;
import com.xgggh.rrrmai.BR;

/**
 * Created by summer on 2018/2/28.
 */
@Entity(indices = {@Index(value = "id",unique = true)})
public class Post extends  BaseObservable implements Parcelable {
    //post id
    @PrimaryKey(autoGenerate = true)
    private long rowsNum;

    public long getRowsNum() {
        return rowsNum;
    }

    public void setRowsNum(long rowsNum) {
        this.rowsNum = rowsNum;
    }

    @NonNull
    private String id;
    //comment user
    private String userId;
    private String userMobile;
    private String userName;

    //提交id
    private String commiter;
    //内容
    private String content;
    //查看次数
    private Long views;
    //引用次数
    private Long refer;
    //时间
    private String date;
    //提交类型
    private String type;



    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public String getUserMobile() {
        return userMobile;
    }

    public void setUserMobile(String userMobile) {
        this.userMobile = userMobile;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    @Override
    public int hashCode() {
        if (id==null){
         return  super.hashCode();
        }
        return id.hashCode();
    }
    
    public Post(){}

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }


    public String getCommiter() {
        return commiter;
    }

    public void setCommiter(String commiter) {
        this.commiter = commiter;
    }


    @Bindable
    public Long getViews() {
        return views;
    }

    public void setViews(Long views) {
        this.views = views;
        notifyPropertyChanged(BR.views);
    }

    public Long getRefer() {
        return refer;
    }

    public void setRefer(Long refer) {
        this.refer = refer;
    }

    public String getDate() {
        return date;
    }

    public void setDate(String date) {
        this.date = date;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }


    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(this.id);
        dest.writeString(this.userId);
        dest.writeString(this.userMobile);
        dest.writeString(this.userName);
        dest.writeString(this.commiter);
        dest.writeString(this.content);
        dest.writeValue(this.views);
        dest.writeValue(this.refer);
        dest.writeString(this.date);
        dest.writeString(this.type);
    }

    protected Post(Parcel in) {
        this.id = in.readString();
        this.userId = in.readString();
        this.userMobile = in.readString();
        this.userName = in.readString();
        this.commiter = in.readString();
        this.content = in.readString();
        this.views = (Long) in.readValue(Long.class.getClassLoader());
        this.refer = (Long) in.readValue(Long.class.getClassLoader());
        this.date = in.readString();
        this.type = in.readString();
    }

    public static final Creator<Post> CREATOR = new Creator<Post>() {
        @Override
        public Post createFromParcel(Parcel source) {
            return new Post(source);
        }

        @Override
        public Post[] newArray(int size) {
            return new Post[size];
        }
    };
}